package za.org.jcicada.syshealth;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.swing.AbstractListModel;

import za.org.jcicada.genss.ServiceURN;

public class ServiceModel extends AbstractListModel {

	private static final long serialVersionUID = 1L;
	private List<ServiceURN> urns = new ArrayList<ServiceURN>();

	public void setElements(Set<ServiceURN> serviceURNs) {
		int previousSize = urns.size();
		urns = new ArrayList<ServiceURN>(serviceURNs);
		fireContentsChanged(this, 0, Math.max(previousSize, urns.size()));
	}
	
	public void addElement(ServiceURN serviceURN) {
		urns.add(serviceURN);
		fireContentsChanged(this, urns.size() - 1, urns.size());
	}
	
	public void removeElement(ServiceURN serviceURN) {
		int index = urns.indexOf(serviceURN);
		urns.remove(serviceURN);
		fireContentsChanged(this, index, urns.size());
	}

	public Object getElementAt(int arg0) {
		return urns.get(arg0);
	}

	public int getSize() {
		return urns.size();
	}
	
	public void clear() {
		int previousSize = getSize();
		urns.clear();
		fireIntervalRemoved(this, 0, previousSize);
	}

}
